package com.example.manu_facturer_orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manu_facturer_orders.pojo.EnginnerVO;
import com.example.manu_facturer_orders.pojo.PageResult;
import com.example.manu_facturer_orders.service.EngineerService;
import commons.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: tobed
 * @date: 2022/9/12
 * @time: 11:03
 */
@RestController
@RequestMapping("engineer")
public class EngineerController {

    @Autowired
    EngineerService engineerService;

    /**
     * 工程师查询
     * @param userCode
     * @param userName
     * @param pageResult
     * @return
     */
    @RequestMapping("listEngineer")
    public Result listEngineer(
            @RequestParam String userCode,
            @RequestParam String userName,
            @RequestParam Integer contractStatus,
            PageResult pageResult){
        Page<EnginnerVO> enginnerVOPage = engineerService.listEngineer(userCode, userName,contractStatus, new Page<>(pageResult.getPageNum(), pageResult.getPageSize()));
        return Result.success(enginnerVOPage);
    }

    /**
     * 解约工程师
     * @param id
     * @return
     */
    @RequestMapping("terminationEngineer")
    public Result terminationEngineer(@RequestParam Integer id){
        Result result = engineerService.terminationEngineer(id);
        return result;
    }

    /**
     * 启用&停用工程师
     * @param id
     * @return
     */
    @DeleteMapping("stopOrOpenEngineer")
    public Result stopOrOpenEngineer(@RequestParam Integer id,@RequestParam Integer contractStatus){
        Result result = engineerService.stopOrOpenEngineer(id,contractStatus);
        System.out.println(id);
        return result;
    }

    /**
     * 无分页全查未签约
     * @return
     */
    @PostMapping("listEngineerNoPage")
    public Result listEngineerNoPage(){
        Result result = engineerService.listEngineerNoPage();
        return result;
    }

    /**
     * 批量签约工程师
     * @param id
     * @return
     */
    @GetMapping("contractEngineer")
    public Result contractEngineer(@Param("id") String id){
        System.out.println(id);
        Result result = engineerService.contractEngineer(id);
        return result;
    }



}
